//
//  BelleViewController.m
//  PhoenixNews
//
//  Created by dllo on 16/1/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BelleViewController.h"
#import "PhoneixNews.pch"
#import "BelleTableViewCell.h"
#import "RecommentClickModel.h"
#import "DetaileBelleViewController.h"
@interface BelleViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *mutbaleArray;

@end

@implementation BelleViewController
- (void)dealloc {
    [_tableView release];
    [_mutbaleArray release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 130) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[BelleTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    [self getData];
    
}
#pragma mark 数据解析
- (void)getData {
     AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    [sessionManager GET:Belle parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = responseObject;
        NSArray *array = dic[@"body"];
        self.mutbaleArray = [RecommentClickModel modelHanderWithArray:array];
        [_tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

#pragma mark - TableView协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _mutbaleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (_mutbaleArray.count != 0 ) {
        BelleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        RecommentClickModel *recomment = _mutbaleArray[indexPath.row];
        [cell.imageUrl sd_setImageWithURL:[NSURL URLWithString:recomment.thumbnail]];
        cell.likes.text = [NSString stringWithFormat:@"%@", recomment.likes];
        cell.image.image = [UIImage imageNamed:@"good"];
        cell.comment.text = [NSString stringWithFormat:@"%@", recomment.commentsall];
        cell.imageCommect.image = [UIImage imageNamed:@"imageComments"];
        return cell;

    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 700;
}
// cell点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetaileBelleViewController *detail = [[DetaileBelleViewController alloc] init];
     RecommentClickModel *recomment = _mutbaleArray[indexPath.row];
     detail.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    detail.imageStr = recomment.thumbnail;
    [self presentViewController:detail animated:YES completion:nil];
   
  

        

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
